<table class="tablesorter" cellspacing="0" style="width:700px;"> 
    <thead> 
        <tr> 
            <th width="39">STT</th>
            <th width="607">Tiêu đề menu</th>
            <th width="30">
                Thêm
                <input type="checkbox" name="viewall" id="checkviewall" style="margin-left: 12px;"/>
            </th>
            <th width="30" align="center">
                Sửa
                <input type="checkbox" name="editall" id="checkeditall"/>
            </th>
            <th width="30" align="center">
                Xóa
                <input type="checkbox" name="deleteall" id="checkdeleteall"/>
            </th>                                
        </tr> 						
    </thead> 
    <tbody> 
        <?php 
            $i = 1;            
            foreach( $arr_Menu as $value ) {                
        ?>
        <tr>            
            <td style="text-align: center"><?php echo $i; ?></td>
            <td><?php echo $value['Menu']['tenmenu']; ?></td>
            <?php 
                $check = true;
                foreach( $arr_Quyen as $value1 ){ 
                    if( $value['Menu']['id'] == $value1['Quyen']['menuid'] ){
                        $check = false;
                ?>
            <td><input type="checkbox" name="data[Quyen][save][<?php echo $value['Menu']['id']; ?>]" class="add" value="<?php echo $value['Menu']['id']; ?>" <?php if( $value1['Quyen']['xem'] == 1 ) echo 'checked';?> /></td>
            <td><input type="checkbox" name="data[Quyen][edit][<?php echo $value['Menu']['id']; ?>]" class="edit" value="<?php echo $value['Menu']['id']; ?>" <?php if( $value1['Quyen']['sua'] == 1 ) echo 'checked';?>/></td>
            <td><input type="checkbox" name="data[Quyen][delete][<?php echo $value['Menu']['id']; ?>]" class="delete" value="<?php echo $value['Menu']['id']; ?>" <?php if( $value1['Quyen']['xoa'] == 1 ) echo 'checked';?>/></td>
            <?php }}
                if($check){
                 ?>
                 <td><input type="checkbox" name="data[Quyen][save][<?php echo $value['Menu']['id']; ?>]" class="add" value="<?php echo $value['Menu']['id']; ?>" /></td>
                <td><input type="checkbox" name="data[Quyen][edit][<?php echo $value['Menu']['id']; ?>]" class="edit" value="<?php echo $value['Menu']['id']; ?>" /></td>
                <td><input type="checkbox" name="data[Quyen][delete][<?php echo $value['Menu']['id']; ?>]" class="delete" value="<?php echo $value['Menu']['id']; ?>" /></td>
            <?php
                }   
            ?>
        </tr>        
        <?php 
            $i++;
            }
        ?>
    </tbody> 
</table> 
<script type="text/javascript">
$("#checkviewall").click(function () {
          $('.add').attr('checked', this.checked);
});
$(".add").click(function(){ 
    if($(".add").length == $(".add:checked").length) {
        $("#checkviewall").attr("checked", "checked");
    } else {
        $("#checkviewall").removeAttr("checked");
    }

});
$("#checkeditall").click(function () {
          $('.edit').attr('checked', this.checked);
});
$(".edit").click(function(){ 
    if($(".edit").length == $(".edit:checked").length) {
        $("#checkeditall").attr("checked", "checked");
    } else {
        $("#checkeditall").removeAttr("checked");
    }

});
$("#checkdeleteall").click(function () {
          $('.delete').attr('checked', this.checked);
});
$(".delete").click(function(){ 
    if($(".delete").length == $(".delete:checked").length) {
        $("#checkdeleteall").attr("checked", "checked");
    } else {
        $("#checkdeleteall").removeAttr("checked");
    }

});
</script>